]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensionPrefs: Hook up kill switch to D-Bus property
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 5 Mar 2020 17:46:18 +0000 (18:46 +0100)
committerFlorian Müllner <florian.muellner@gmail.com>
Thu, 19 Mar 2020 14:27:36 +0000 (14:27 +0000)
Now that the org.gnome.Shell.Extensions interface exposes the
disable-user-extensions setting on D-Bus, we can use that instead
of the shell's GSettings.

In a future where we distribute the app separately as flatpak, this
will require one less hole in the sandbox.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1081

js/extensionPrefs/data/ui/extensions-window.ui
js/extensionPrefs/js/main.js

index c88375b1bde41aa4c14c30c4fed8969cac4e5c45..619582355a05b133b710504a613a365efc0cf717 100644 (file)
@@ -90,8 +90,9 @@
           </packing>
         </child>
         <child>
-          <object class="GtkSwitch" id="killSwitch">
+          <object class="GtkSwitch">
             <property name="visible">True</property>
+            <property name="action-name">win.user-extensions-enabled</property>
           </object>
           <packing>
             <property name="pack_type">end</property>
index e4e2328c613c229465641ed44db29109c4597947..aa325ea92e0b7a946208533c65f55bbf278913d8 100644 (file)
@@ -36,6 +36,11 @@ function stripPrefix(string, prefix) {
     return string;
 }
 
+function toggleState(action) {
+    let state = action.get_state();
+    action.change_state(new GLib.Variant('b', !state.get_boolean()));
+}
+
 var Application = GObject.registerClass(
 class Application extends Gtk.Application {
     _init() {
@@ -94,7 +99,6 @@ var ExtensionsWindow = GObject.registerClass({
     InternalChildren: [
         'userList',
         'systemList',
-        'killSwitch',
         'mainBox',
         'mainStack',
         'scrolledWindow',
@@ -121,10 +125,15 @@ var ExtensionsWindow = GObject.registerClass({
         action.connect('activate', this._logout.bind(this));
         this.add_action(action);
 
-        this._settings = new Gio.Settings({ schema_id: 'org.gnome.shell' });
-        this._settings.bind('disable-user-extensions',
-            this._killSwitch, 'active',
-            Gio.SettingsBindFlags.DEFAULT | Gio.SettingsBindFlags.INVERT_BOOLEAN);
+        action = new Gio.SimpleAction({
+            name: 'user-extensions-enabled',
+            state: new GLib.Variant('b', false),
+        });
+        action.connect('activate', toggleState);
+        action.connect('change-state', (a, state) => {
+            this._shellProxy.UserExtensionsEnabled = state.get_boolean();
+        });
+        this.add_action(action);
 
         this._userList.set_sort_func(this._sortList.bind(this));
         this._userList.set_header_func(this._updateHeader.bind(this));
@@ -135,6 +144,10 @@ var ExtensionsWindow = GObject.registerClass({
         this._shellProxy.connectSignal('ExtensionStateChanged',
             this._onExtensionStateChanged.bind(this));
 
+        this._shellProxy.connect('g-properties-changed',
+            this._onUserExtensionsEnabledChanged.bind(this));
+        this._onUserExtensionsEnabledChanged();
+
         this._scanExtensions();
     }
 
@@ -388,6 +401,12 @@ var ExtensionsWindow = GObject.registerClass({
         ].find(c => c.uuid === uuid);
     }
 
+    _onUserExtensionsEnabledChanged() {
+        let action = this.lookup_action('user-extensions-enabled');
+        action.set_state(
+            new GLib.Variant('b', this._shellProxy.UserExtensionsEnabled));
+    }
+
     _onExtensionStateChanged(proxy, senderName, [uuid, newState]) {
         let extension = ExtensionUtils.deserializeExtension(newState);
         let row = this._findExtensionRow(uuid);
@@ -632,10 +651,7 @@ var ExtensionRow = GObject.registerClass({
             name: 'enabled',
             state: new GLib.Variant('b', false),
         });
-        action.connect('activate', () => {
-            let state = action.get_state();
-            action.change_state(new GLib.Variant('b', !state.get_boolean()));
-        });
+        action.connect('activate', toggleState);
         action.connect('change-state', (a, state) => {
             if (state.get_boolean())
                 this._app.shellProxy.EnableExtensionRemote(this.uuid);